package com.grm.sys.service.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.grm.sys.entity.SysUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 系统用户映射器
 *
 * @author gaorimao
 * @date 2022/06/24
 */
public interface SysUserMapper extends BaseMapper<SysUser> {
    /**
     * 下拉框时，查询用户
     *
     * @return sysUsers
     */
    @Select("select username as label,username as `value` from sys_user")
    List<Map<String, String>> queryUserOptions();

    @Update("update sys_user set `password` = #{password} where username = #{username}")
    void updatePasswordByUsername(@Param("username") String username, @Param("password")String password);

    @Update("update sys_user set `avatar` = #{avatar} where username = #{username}")
    void updateAvatar(@Param("username") String username, @Param("avatar")String avatar);

    @Select("select count(1) from sys_role sr left join sys_user_role sur on sr.id = sur.role_id where sur.user_id = #{userId} " +
            "and sr.code = 'project_manager'")
    Integer isProjectMangerRole(Long id);
}
